package com.sk.bilibili.view.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.sk.bilibili.R;
import com.sk.bilibili.adapter.vlayout.BaseVideoSetAdapter;
import com.sk.bilibili.databinding.ActivityBaseVideoSetBinding;
import com.sk.bilibili.model.BaseModel;
import com.sk.bilibili.view.diy.bottomDialog.LaterBottomDialog;
import com.sk.bilibili.view.fragment.main.LaterFragment;

import java.util.List;

public abstract class BaseVideoSetActivity<M extends BaseModel,D> extends BaseActivity<ActivityBaseVideoSetBinding,M> {

    protected static void start(Context context,Integer memberId,Class<?extends BaseVideoSetActivity> clazz){
        Intent intent = new Intent(context, clazz);
        intent.putExtra("id",memberId);
        context.startActivity(intent);
    }

    protected Integer memberId;
    private LaterBottomDialog laterBottomDialog;

    @Override
    protected void afterSetView() {
        initView();
        bindEvent();
        memberId= (Integer) getIntent().getSerializableExtra("id");
    }

    private void bindEvent() {
        bind.ivBack.setOnClickListener(v->finish());
        bind.ivSearch.setOnClickListener(v->SearchActivity.start(this,null));
    }

    private BaseVideoSetAdapter<D> videoSetAdapter;

    private void initView() {
        laterBottomDialog=new LaterBottomDialog();
        bind.tvTitle.setText(getTitleName());
        VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
        bind.rvShow.setLayoutManager(layoutManager);
        DelegateAdapter adapter = new DelegateAdapter(layoutManager);
        videoSetAdapter = getAdapter();
        adapter.addAdapter(videoSetAdapter);
        bind.rvShow.setAdapter(adapter);
    }

    protected abstract BaseVideoSetAdapter<D> getAdapter();

    protected abstract String getTitleName();

    public void loadDataSuccess(List<D> list){
        videoSetAdapter.setData(list);
    }

    public void onThemClick(Integer id) {
        ThemActivity.start(this,id);
    }

    public void onVideoSetClick(Integer id) {
        VideoSetActivity.start(this,id);
    }

    public void onMoreClick(Integer id) {
        laterBottomDialog.show(getSupportFragmentManager(),id);
    }

}